package vn.com.demand.lux.model;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

import vn.com.demand.util.DpUtils;

public class ServiceCardManager {
	
	public static void saveServiceCards(List<ServiceCardBean> list) throws SQLException {
		if (null != list && !list.isEmpty()) {
			Connection conn = DpUtils.getConnection();
			try {
				conn.setAutoCommit(false);
				//other connection/transaction may be waited this transaction/connection completed
				conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
				QueryRunner runner = new QueryRunner();
				for (ServiceCardBean bean : list) {
					bean.saveOrUpdate(conn, runner);
				}
				conn.commit();
			} catch (SQLException e) {
				conn.rollback();
				throw e;
			} finally {
				DpUtils.releaseConnection(conn);
			}
		}
	}
	
}
